package com.ruoyi.system.service.impl;


import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.CostRequest;
import com.ruoyi.system.domain.vo.zbg.AnnualCostDataVo;
import com.ruoyi.system.domain.vo.zbg.MonthlyRepairDataVo;
import com.ruoyi.system.domain.vo.zbg.RepairDateVo;
import com.ruoyi.system.domain.zbg.CostData;
import com.ruoyi.system.domain.zbg.MonthlyRepairData;
import com.ruoyi.system.mapper.CostDataMapper;
import com.ruoyi.system.mapper.MonthlyRepairDataMapper;
import com.ruoyi.system.service.CostDataService;
import com.ruoyi.system.service.MonthlyRepairDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CostDataServiceImpl extends ServiceImpl<CostDataMapper, CostData> implements CostDataService {
    @Autowired
    private CostDataMapper costDataMapper;
    //防止错误出现，所以回滚事务
    @Autowired
    private MonthlyRepairDataMapper monthlyRepairDataMapper;
    @Transactional(rollbackFor = Exception.class)
    public void saveAll(List<CostData> costDataList) {
        for (CostData costData : costDataList) {
//            判断是否有年月，如果没有获取当前年，月
            if (ObjectUtils.isEmpty(costData.getCostYear())) {
                costData.setCostYear(DateUtils.getNowYear());
            }
            if (ObjectUtils.isEmpty(costData.getCostMonth())){
                costData.setCostMonth(DateUtils.getNowMonth());
            }
                costDataMapper.saveOrUpdate(costData);

        }
    }



}